package com.qdsg.ysg.doctor.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.util.ToastUtil;
import com.rest.response.DateTime;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Description
 * Created by lbj on 2022/4/7 14:29
 */

public class DateAdapter extends RecyclerView.Adapter<DateAdapter.ViewHolder> {


    private Context mContext;
    private List<DateTime> dateList;
    private OnItemClickLitener mOnItemClickLitener;


    public DateAdapter(Context context, List<DateTime> list) {
        this.mContext = context;
        this.dateList = list;
    }



    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
        ViewHolder myHolder;
        myHolder = new ViewHolder( LayoutInflater.from( mContext ).inflate( R.layout.item_date, parent, false ) );
        return myHolder;

    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NotNull ViewHolder holder, final int position) {

        if (dateList.get( position ).isSelect) {
            holder.tvDate.setTextColor( ContextCompat.getColor( mContext, R.color.white ) );
            holder.container.setBackgroundResource( R.drawable.shape_solid_ff8ecac1);
        } else {
            holder.tvDate.setTextColor( ContextCompat.getColor( mContext, R.color.ff666666 ) );
            holder.container.setBackgroundResource( R.drawable.shape_solid_ffecf7f5 );
        }
        if (position == 0) {
            holder.tvDate.setText( "今日" );
        } else {
            holder.tvDate.setText( dateList.get( position ).date );
        }


        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener( v -> {
                mOnItemClickLitener.onItemClick( holder.itemView, position );

            } );
        }

    }

    @Override
    public int getItemCount() {
        return dateList.size();
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }


    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.container)
        RelativeLayout container;

        public ViewHolder(View itemView) {
            super( itemView );
            ButterKnife.bind( this, itemView );
        }
    }

}
